import { EggAppConfig, EggAppInfo, PowerPartial, Context } from 'egg';

export default (appInfo: EggAppInfo) => {
  const config = {} as PowerPartial<EggAppConfig>;

  // override config from framework / plugin
  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1709015754331_2781';

  // 全局异常处理
  config.onerror = {
    all(err: Error, ctx: Context) {
      ctx.body = {
        code: 500,
        message: err.message,
      };
      ctx.status = 500;
    },
  };

  // 全局中间件
  config.middleware = ['auth'];

  config.jwt = {
    secret: 'xZN7aVrZYFsBF7W6dNnE.C2Y',
    sign: {
      expiresIn: '3d',
    },
  };
  config.ignoreAuth = ['/api/login'];

  // add your special config in here

  // the return config will combines to EggAppConfig
  return {
    ...config,
  };
};
